package cl.whyem.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cl.whyem.dto.CustomerDTO;
import cl.whyem.service.CustomerLookup;

@ManagedBean(eager=true)
@ApplicationScoped
public class CustomerLookupImpl implements CustomerLookup {

	private static Logger logger = LoggerFactory.getLogger(CustomerLookupImpl.class);
	
	private Map<String, CustomerDTO> customerMap;
	
	public CustomerLookupImpl() {
		logger.info(">>> Autowireando al deploy(eager=true), con DI JSF <<<");
		
		this.customerMap = new HashMap<String, CustomerDTO>();
		customerMap.put("admin", new CustomerDTO(1000000, "admin", "Yamil", "Medina"));
		customerMap.put("user", new CustomerDTO(511, "user", "Usuario Name"));
		customerMap.put("nada", new CustomerDTO(0, "nada"));
	}
	
	@Override
	public CustomerDTO findByUsuario(String usuario) {
		return customerMap.get(usuario.toLowerCase());
	}
	
	public Map<String, CustomerDTO> getCustomerMap() {
		return customerMap;
	}
	
	public void setCustomerMap(Map<String, CustomerDTO> customerMap) {
		this.customerMap = customerMap;
	}
}
